from collections import deque
import re

# 使用yield进行字符串匹配
def demo_1():
    line_1 = "kepler this is test for kepler adfafasdd"
    line_2 = "this is test for kepler faagwe"
    pattern = r'kepler'
    # re.match尝试从字符串的起始位置匹配一个模式，如果不是起始位置匹配成功的话，match()就返回none
    result_1 = re.match(pattern, line_1)
    print(result_1)
    result_2 = re.search(pattern, line_2)
    print(result_2)


# deque函数会新建一个固定大小的队列，当新的元素加入并且这个队列已满时，最好的元素会自动被移除掉
def demo_2():
    test_deque = deque(maxlen=3)
    test_deque.append(1)
    test_deque.append(2)
    test_deque.append(3)
    print(test_deque)
    test_deque.append(4)
    print(test_deque)

def demo_3():
    test_deque = deque(maxlen=3)
    test_deque.append(1)
    test_deque.append(2)
    test_deque.append(3)
    print(test_deque)
    test_deque.appendleft(4)
    print(test_deque)
    test_deque.pop()
    print(test_deque)

if __name__ == '__main__':
    # demo_1()
    # demo_2()
    demo_3()